package com.zoffy.wmsbackend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zoffy.wmsbackend.model.echart.StockInSummaryByWarehouse;
import com.zoffy.wmsbackend.model.echart.StockOutSummaryByWarehouse;
import com.zoffy.wmsbackend.model.echart.StockOutAmountSummaryByWarehouse;
import com.zoffy.wmsbackend.model.entity.ReportDaySummaryStockIn;
import com.zoffy.wmsbackend.model.entity.ReportDaySummaryStockOut;
import com.zoffy.wmsbackend.model.vo.report.GoodsQuantity;
import com.zoffy.wmsbackend.model.vo.report.StockDiffQuantity;
import com.zoffy.wmsbackend.model.vo.report.SummaryDayStockIn;
import com.zoffy.wmsbackend.model.vo.report.SummaryDayStockOut;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ChartMapper extends BaseMapper<StockInSummaryByWarehouse> {

    @Select("SELECT w.warehouse_code, COUNT(sio.id) as stock_in_count, w.warehouse_name " +
            "FROM warehouse w " +
            "LEFT JOIN stock_in_order sio ON w.id = sio.warehouse_id AND sio.status = 90 " +
            "GROUP BY w.warehouse_code, w.warehouse_name ORDER BY stock_in_count desc")
    List<StockInSummaryByWarehouse> getStockInCountByWarehouse();

    @Select("SELECT w.warehouse_code, COUNT(soo.id) as stock_out_count, w.warehouse_name " +
            "FROM warehouse w " +
            "LEFT JOIN stock_out_order soo ON w.id = soo.warehouse_id AND soo.status = 90 " +
            "GROUP BY w.warehouse_code, w.warehouse_name ORDER BY stock_out_count desc")
    List<StockOutSummaryByWarehouse> getStockOutCountByWarehouse();

    List<StockOutAmountSummaryByWarehouse> getStockOutAmountSummaryByWarehouse();

    List<SummaryDayStockIn> getSummaryDayStockIn(String startTime, String endTime);

    List<ReportDaySummaryStockIn> getSummaryDayStockInByTime(String time);

    List<SummaryDayStockOut> getSummaryDayStockOut(String startTime, String endTime);

    List<ReportDaySummaryStockOut> getSummaryDayStockOutByTime(String time);

    List<StockDiffQuantity> getStockDiffQuantity();
    List<GoodsQuantity> getStockInGoodsQuantity();
    List<GoodsQuantity> getStockOutGoodsQuantity();
}